<template>
  <div>
    <h1>参团</h1>
    <div>
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="活动名称">
          <el-input
            v-model="searchForm.statusId"
            placeholder="请输入活动名称"
            clearable
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="getGroup()">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table :data="groupJoinData" border style="width: 100%">
        <el-table-column prop="groudId" label="Id" />
        <el-table-column prop="joinId" label="活动名称" />
        <el-table-column prop="teamHeader" label="描述" />
        <el-table-column prop="teamLimit" label="单位" />
        <el-table-column prop="joinNum" label="开始时间" />
        <el-table-column prop="beginTime" label="结束时间" />
        <el-table-column prop="endTime" label="参团人数" />
        <el-table-column prop="groupStatus" label="购买限制人数" />
      </el-table>
    </div>
    <div>
      <el-pagination
        v-model:current-page="searchForm.pageNum"
        v-model:page-size="searchForm.pageSize"
        :page-sizes="[2, 4, 6, 8]"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getGroupList } from "../api/api";

const groupJoinData = ref([]);
const searchForm = ref({
  pageNum: 1,
  pageSize: 2,

  statusId: null,
});
const total = ref(0);
const getGroup = () => {
  getGroupList(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      groupJoinData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  getGroup();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  getGroup();
};

onMounted(() => {
  getGroup();
});
</script>

<style scoped></style>
